/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bmf.pojo;
import common.InvalidPacketParametersException;
import communication.IConfigurationPacket;
import java.util.ArrayList;

/**
 *
 * @author Tony_
 */
public class BMFrequest {
        IConfigurationPacket request;
	ArrayList<BMFNode> nodes;
	String name;
	boolean active;
	boolean isAggregation;
        
        public BMFrequest(BMFrequest req, IConfigurationPacket newReq) {
		this.active=req.active;
		this.isAggregation=req.isAggregation;
		this.name=req.name;
		this.nodes=req.nodes;
		this.request=clone(req.request, newReq);
	}

	private IConfigurationPacket clone(IConfigurationPacket request2, IConfigurationPacket newReq) {
		try {
			newReq.setAction(request2.getAction());
                        newReq.setActuatorParams(request2.getActuatorParams());
                        newReq.setConfigurationType(request2.getConfigurationType());
                        newReq.setDataType(request2.getDataType());
                        newReq.setDestination(request2.getDestination());
                        newReq.setLifetimeTimescale(request2.getLifetimeTimescale());
                        newReq.setLifetimeValue(request2.getLifetimeValue());
                        newReq.setPeriodTimescale(request2.getPeriodTimescale());
			newReq.setPeriodValue(request2.getPeriodValue());
		} catch (InvalidPacketParametersException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
                        newReq.setSensor_actuatorType(request2.getSensor_actuatorType());
                        newReq.setSensorIfThreshold(request2.getSensorIfThreshold());
		if(request2.getSensorTypeMoreThreshold()!=null)
                        newReq.setSensorTypeMoreThreshold(request2.getSensorTypeMoreThreshold());
                        newReq.setSyntheticData(request2.getSyntheticData());
                        newReq.setThresholdNumber(request2.getThresholdNumber());
		if(request2.getThresholdType()!=null)
                        newReq.setThresholdType(request2.getThresholdType());
		if(request2.getThresholdValue()!=null)
                        newReq.setThresholdValue(request2.getThresholdValue());
		return newReq;
	}
        
	public BMFrequest(String name, IConfigurationPacket request, ArrayList<BMFNode> nodes, boolean isAggregation) {
		super();
		this.request = request;
		this.name=name;		
		this.nodes=nodes;
		active=true;
                this.isAggregation=isAggregation;
	}

        /**
		 * @return
		 * @uml.property  name="isAggregation"
		 */
        public boolean isAggregation(){
            return isAggregation;
        }
	
        public void setActive(boolean active) {
		this.active = active;
	}
	/**
	 * @return  the request
	 * @uml.property  name="request"
	 */
	public IConfigurationPacket getRequest() {
		return request;
	}

	public ArrayList<BMFNode> getResult() {
		// TODO Auto-generated method stub
		return nodes;
	}

}

